package ch07.home;

class Exercise7_02 {
	public static void main(String args[]) {
		SutdaDeck02 deck = new SutdaDeck02();

		System.out.println(deck.pick(0)); // 1K
		System.out.println(deck.pick()); // 8
		deck.shuffle();

		for (int i = 0; i < deck.cards.length; i++)
			System.out.print(deck.cards[i] + " ");
		// 1 8 6 6 5 4 7 8K 10 2 3 7 5 4 9 1K 3K 2 10 9 

		System.out.println();
		System.out.println(deck.pick(0)); // 2
	}
}

class SutdaDeck02 {
	final int CARD_NUM = 20;
	SutdaCard[] cards = new SutdaCard[CARD_NUM];

	SutdaDeck02() {
		for (int i = 0, n = 1; i < cards.length; i++, n++) {
			boolean isKwang = false;

			isKwang = i < 10 && (n == 1 || n == 3 || n == 8);
			n = (n % 10 == 0) ? 10 : n % 10;

			cards[i] = new SutdaCard(n, isKwang);
		}
	}

	// <1
	void shuffle() {
		for (int x = 0; x < cards.length * 2; x++) {			
			int i = (int) (Math.random() * cards.length);
			int j = (int) (Math.random() * cards.length);			
			SutdaCard tmp = cards[i];
			cards[i] = cards[j];
			cards[j] = tmp;
		}
	}

	SutdaCard pick(int index) {
		if (index < 0 || index >= CARD_NUM) return null;
		return cards[index];

	}

	SutdaCard pick() {
		int index = (int) (Math.random() * cards.length);
		return pick(index);
	}
	// 1>

}